package com.guigui.gulimall.product.controller.web;

import com.guigui.gulimall.product.entity.CategoryEntity;
import com.guigui.gulimall.product.service.CategoryService;
import com.guigui.gulimall.product.vo.web.CatalogListWebVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author xin
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/","/index.html","/index"})
    public String index(Model model) {
        List<CategoryEntity> catLevelOne = categoryService.getCatalogLevelOne();
        model.addAttribute("catalogs", catLevelOne);
        return "index";
    }

    /**
     * 前端分类json展示页
     */
    @GetMapping("/index/json/catalog.json")
    @ResponseBody
    public Map<String, List<CatalogListWebVo>> getCatalogJson() {
        return categoryService.getCatalogJson();
    }
}
